﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.SpcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.SpcManagement.SpcAnalysisVMs
{
    public partial class SpcAnalysisListVM : BasePagedListVM<SpcAnalysis_View, SpcAnalysisSearcher>
    {
        
        protected override IEnumerable<IGridColumn<SpcAnalysis_View>> InitGridHeader()
        {
            return new List<GridColumn<SpcAnalysis_View>>{
                
                this.MakeGridHeader(x => x.SpcAnalysis_Code).SetTitle(@Localizer["Page.表单编号"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_Desc).SetTitle(@Localizer["Page.表单描述"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_ChartType).SetTitle(@Localizer["Page.控制图样式"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_OpId).SetTitle(@Localizer["Page.工序"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_OpName).SetTitle(@Localizer["Page.工序名称"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_ChartName).SetTitle(@Localizer["Page.图表名称"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_DataName).SetTitle(@Localizer["Page.数据名称"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_DataTag).SetTitle(@Localizer["Page.数据Tag"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_SimpleQty).SetTitle(@Localizer["Page.抽样数量"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_UCL).SetTitle(@Localizer["Page.上控制限"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_CL).SetTitle(@Localizer["Page.中心线"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_LCL).SetTitle(@Localizer["Page.下控制限"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_USL).SetTitle(@Localizer["Page.规格上限"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_LSL).SetTitle(@Localizer["Page.规格下限"].Value),
                this.MakeGridHeader(x => x.SpcAnalysis_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<SpcAnalysis_View> GetSearchQuery()
        {
            var query = DC.Set<SpcAnalysis>()
                
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.Desc, x=>x.Desc)
                .CheckEqual(Searcher.ChartType, x=>x.ChartType)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpName, x=>x.OpName)
                .CheckContain(Searcher.ChartName, x=>x.ChartName)
                .CheckContain(Searcher.DataName, x=>x.DataName)
                .CheckContain(Searcher.DataTag, x=>x.DataTag)
                .CheckEqual(Searcher.SimpleQty, x=>x.SimpleQty)
                .CheckEqual(Searcher.UCL, x=>x.UCL)
                .CheckEqual(Searcher.CL, x=>x.CL)
                .CheckEqual(Searcher.LCL, x=>x.LCL)
                .CheckEqual(Searcher.USL, x=>x.USL)
                .CheckEqual(Searcher.LSL, x=>x.LSL)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new SpcAnalysis_View
                {
				    ID = x.ID,
                    
                    SpcAnalysis_Code = x.Code,
                    SpcAnalysis_Desc = x.Desc,
                    SpcAnalysis_ChartType = x.ChartType,
                    SpcAnalysis_ProductId = x.ProductId,
                    SpcAnalysis_ProductName = x.ProductName,
                    SpcAnalysis_OpId = x.OpId,
                    SpcAnalysis_OpName = x.OpName,
                    SpcAnalysis_ChartName = x.ChartName,
                    SpcAnalysis_DataName = x.DataName,
                    SpcAnalysis_DataTag = x.DataTag,
                    SpcAnalysis_SimpleQty = x.SimpleQty,
                    SpcAnalysis_UCL = x.UCL,
                    SpcAnalysis_CL = x.CL,
                    SpcAnalysis_LCL = x.LCL,
                    SpcAnalysis_USL = x.USL,
                    SpcAnalysis_LSL = x.LSL,
                    SpcAnalysis_Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class SpcAnalysis_View: SpcAnalysis
    {
        
        public string SpcAnalysis_Code { get; set; }
        public string SpcAnalysis_Desc { get; set; }
        public SpcChartTypeEnum? SpcAnalysis_ChartType { get; set; }
        public long? SpcAnalysis_ProductId { get; set; }
        public string SpcAnalysis_ProductName { get; set; }
        public long? SpcAnalysis_OpId { get; set; }
        public string SpcAnalysis_OpName { get; set; }
        public string SpcAnalysis_ChartName { get; set; }
        public string SpcAnalysis_DataName { get; set; }
        public string SpcAnalysis_DataTag { get; set; }
        public int? SpcAnalysis_SimpleQty { get; set; }
        public decimal? SpcAnalysis_UCL { get; set; }
        public decimal? SpcAnalysis_CL { get; set; }
        public decimal? SpcAnalysis_LCL { get; set; }
        public decimal? SpcAnalysis_USL { get; set; }
        public decimal? SpcAnalysis_LSL { get; set; }
        public string SpcAnalysis_Remark { get; set; }

    }

}